package socketmvc.server.processor;

import socketmvc.core.packets.biz.SockMultiFile;
import socketmvc.core.processor.annotation.*;
import socketmvc.server.context.SocketChannel;
import java.io.File;
import java.util.HashMap;
import java.util.List;

@SocketControl
public class DemoProcessor implements IBaseProcessor {


    @SocketResponse(returnName = "dd")
    @SocketCommand("/chat/p1")
    public int p1(
            @SocketParam("age")
            Integer a,
            @SocketParam("name")
            String b,
            @SocketParam("money")
            Double c,
            @SocketParam("friends")
            List<String> d,
            @SocketParam("cars")
                    int e,
            SocketChannel context){
        context.bindUser("123");
//        HashMap<Object, Object> objectObjectHashMap = new HashMap<>();
//        objectObjectHashMap.put("hah","我是结果");
//        objectObjectHashMap.put("thread",Thread.currentThread().getName());
//        this.response(objectObjectHashMap);
        return 1;
    }

    @SocketCommand("/chat/p2")
    public int p2(
            @SocketParam("age")
                    Integer a,
            SocketChannel context){
        context.bindUser("456");
                HashMap<Object, Object> objectObjectHashMap = new HashMap<>();
        objectObjectHashMap.put("hah","我是tcp");
        objectObjectHashMap.put("thread",Thread.currentThread().getName());
        this.sendToUser("123",objectObjectHashMap);
        return 2;
    }


    @SocketResponse(returnName = "俺是大赛第")
    @SocketCommand("/chat/getImg")
    public  File getImg(){
        return new File("/home/xue/桌面/shuma.jpg");
    }

    @SocketCommand("/chat/sendImg")
    public SockMultiFile sendImg(SockMultiFile file){
        return file;
    }

    // 测试 ResponseFuture
    @SocketCommand("/testSync")
    public String testSync(SocketChannel context) throws InterruptedException {
        Thread.sleep(5000);
        return "非常完美的返回";
    }

//    @SocketCommand(value = "/login",root = true)
//    public void login(@SocketBody Map<String,String> packet, SocketChannel context){
//        String deviceId = packet.get("deviceId");
//        String userId = packet.get("userId");
//
//        if(userId != null){
//            context.bindUser(userId);
//        }
//        if(deviceId != null){
//            context.bindUser(deviceId);
//        }
//    }

//    @SocketCommand(value = "/requestCarBoxPlayHistory",root = true)
//    public void play(@SocketBody Map<String,String> packet,  SocketChannel context){
//        String deviceId = packet.get("deviceId");
//        String userId = packet.get("userId");
//        String filename = packet.get("filename");
//        String cameraIndex = packet.get("cameraIndex");
//
//        Map<String, Object> map = new HashMap<>();
//        map.put("filename",filename);
//        map.put("cameraIndex",cameraIndex);
//        map.put("deviceId",deviceId);
//        map.put("userId",userId);
//        JsonBasicPacket simplePacket = ImPacketStaticFactory.createSimplePacket(map);
//        simplePacket.setCommand("/video/playHistory");
//        context.sendToUser(deviceId, simplePacket);
//        // 客户端主动触发关闭socket时回调当前函数
//    }
//
//
//    @SocketCommand(value = "/transferHistoryVideoToClient",root = true)
//    public void transport(@SocketBody Map<String,String> packet, SockFile file,  SocketChannel context){
//        String deviceId = packet.get("deviceId");
//        String userId = packet.get("userId");
//        context.bindUser(deviceId);
//        context.sendToUser(userId, context.getPacket());
//
//        // 客户端主动触发关闭socket时回调当前函数
//    }
}
